<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="Connect.*" import="java.sql.*"%>
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>

</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1>Success</h1>
		<hr></hr>

<%
	String redirect = "index.jsp";
	String username = (String)session.getAttribute("logged_user");
	String username1 = request.getParameter("aucowner");
	String item_id = request.getParameter("itemid");
	String auc_id = request.getParameter("auctionid");
	
	//Getting Auction information
	java.sql.Connection conn = null;
	try {
		// Connect to the database.
		Class.forName(ConnectionInfo.myJDBCDriver()).newInstance();
		java.util.Properties sysprops = System.getProperties();
		sysprops.put("user", ConnectionInfo.myUserID());
		sysprops.put("password", ConnectionInfo.myPassword());
		conn = java.sql.DriverManager.getConnection(ConnectionInfo.myURL(), sysprops);

		// Execute statement information.
		java.sql.Statement statement = conn.createStatement();
		statement.executeUpdate("UPDATE items SET copies_available = copies_available-1," 
				+" copies_sold = copies_sold+1 WHERE items.id='"+ item_id + "'");
		
		statement.executeUpdate("UPDATE customers SET rating = rating+1 WHERE username='"+username1+"'");
		statement.executeUpdate("UPDATE auctions SET in_progress = 1 WHERE id="+auc_id+"");
		java.sql.ResultSet rs = statement.executeQuery("SELECT bidder_username, bid_price FROM bids WHERE auction_id=" + auc_id 
				+ " ORDER BY bid_price DESC");
		rs.next();
		statement.executeUpdate("UPDATE customers SET rating = rating+1 WHERE username='"+rs.getString("bidder_username")+"'");
		
		out.println("<a href=\"" + redirect + "\">Click here if you can't wait!</a>");
		response.setHeader("Refresh", "5; " + redirect);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			conn.close();
		} catch (Exception ee) {
		}
	}
%>
</div>
</body>
</html>